<div class="container-fluid">
    <div class="wrapper">
        <div class="panel" id="nav">
            <div class="panel-heading"><h3 class="panel-title">储位列表</h3></div>
            <div class="panel-body">
                <form action="__URL__/storage_lists" method="get" class="form">
                    <div class="container-fluid">
                        <div class="col-sm-12 col-md-3 add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">储位编码</span>
                                <input type="text" name="storage_position" class="form-control" value="{$Think.get.storage_position}">
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-3 add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">绑定sku</span>
                                <input type="text" name="bind_sku" class="form-control" value="{$Think.get.bind_sku}">
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-3 add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">是否退税</span>
                                <select name="export_tax_rebate" class="form-control">
                                    <option value="">全部</option>
                                    <volist name="export_tax_rebate" id="item">
                                        <option value="{$key}" <if condition="$Think.get.export_tax_rebate neq '' && $Think.get.export_tax_rebate eq $key">selected</if>>{$item}</option>
                                    </volist>
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-3 add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">状态</span>
                                <select name="status" class="form-control">
                                    <option value="">全部</option>
                                    <option value="1" <if condition="$Think.get.status neq '' && $Think.get.status eq 1">selected</if>>可用</option>
                                    <option value="0" <if condition="$Think.get.status neq '' && $Think.get.status eq 0">selected</if>>禁用</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-2 add-space">
                            <input class="btn btn-primary" type="submit" value="查询">
                            <input class="btn btn-primary" type="reset" value="重置">
                        </div>
                    </div>
                </form>
                <div class="clearfix"></div>
                <hr>
                <div class="fixed-table-toolbar">
                </div>

                <table class="table table-striped  table-hover" cellspacing="0" width="100%">
                    <thead>
                    <tr>
                        <th class="text-center">编号</th>
                        <th class="text-center">储位编码</th>
                        <th class="text-center">储位位置</th>
                        <th class="text-center">绑定sku</th>
                        <th class="text-center">主体</th>
                        <th class="text-center">是否退税</th>
                        <th class="text-center">状态</th>
                        <th class="text-center">备注</th>
                        <th class="text-center">创建时间</th>
                        <th class="text-center">操作</th>
                    </tr>
                    </thead>
                    <tbody id="StockIn">
                        <foreach name='result' item='vo'>
                        <tr>
                            <td class="text-center">{$vo.id}</td>
                            <td class="text-center">{$vo.storage_position}</td>
                            <td class="text-center">{$vo.position}</td>
                            <td class="text-center" style="word-break:break-all;">{$vo.bind_sku}</td>
                            <td class="text-center">
                                <if condition="$vo.enterprise_dominant">
                                    {$enterprise_dominant[$vo['enterprise_dominant']]}
                                </if>
                            </td>
                            <td class="text-center">
                                <if condition="$vo.export_tax_rebate eq 1">
                                    出口退税
                                <else />
                                    非出口退税
                                </if>
                            </td>
                            <td class="text-center">
                                <if condition="$vo['status'] eq 1">
                                    可用
                                <else />
                                    禁用
                                </if>
                            </td>
                            <td class="text-center">{$vo.remark}</td>
                            <td class="text-center">{$vo.create_time}</td>
                            <td>
                                <a class="btn btn-xs btn-info" href="{:U('Warehouse/StockIn/edit_storage', array('id' => $vo['id']))}">编辑</a>
                                <button type="button" class="btn btn-xs btn-primary bind-sku" data-toggle="modal" data-sku="{$vo.bind_sku}" data-storage-position="{$vo.storage_position}" data-export-tax-rebate="{$vo.export_tax_rebate}" data-target=".bind-modal">绑定sku</button>
                                
                                <if condition="$vo['status'] eq 1">
                                    <a class="btn btn-xs btn-danger btn-disabled" data-id="{$vo.id}" data-status="0" data-storage="{$vo.storage_position}">禁用</a>
                                <else />
                                    <a class="btn btn-xs btn-danger btn-disabled" data-id="{$vo.id}" data-status="1" data-storage="{$vo.storage_position}">取消禁用</a>
                                </if>
                            </td>
                        </tr>
                        </foreach>
                    </tbody>
                </table>
            </div>
            <div class="clearfix clear"></div>
            <div class="row">
                <div class="col-md-6 pull-left">
                    <label>每页 20 条记录
                        显示 1 到 20 项，共 {$count}项</label>
                </div>
                <div class="col-md-6">
                    <div class="page pull-right" style="padding: 0;margin: 0">
                        {$page}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 绑定sku -->
<div class="modal fade bind-modal">
    <div class="modal-dialog modal-md">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                <h4 class="modal-title">绑定sku</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="" method="post" role="form">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label class="col-md-3 control-label">储位编码：</label>
                                    <div class="col-md-9">
                                        <p class="form-control-static p-storage-position"></p>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">SKU：</label>
                                    <div class="col-md-9">
                                        <input type="text" name="sku" class="form-control" style="width:70%">
                                        <p class="form-control-static">注：多个sku以英文逗号分隔</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <input type="hidden" name="sku_old" />
                <input type="hidden" name="export_tax_rebate" />
                <button type="button" class="btn btn-primary sure-bind" data-storage-position="">确认</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function(){
        //禁用（取消禁用）
        $('.btn-disabled').click(function() {
            var id = $(this).attr('data-id');
            var status = $(this).attr('data-status');
            var storage_position = $(this).attr('data-storage');
            $.ajax({
                type: "post",
                url: 'Warehouse/StockIn/set_storage_status',
                data: {
                    id: id,
                    status: status,
                    storage_position: storage_position,
                },
                dataType: "json",
                success: function (result) {
                    if (result.status) {
                        layer.msg(result.info, {icon: 6});
                        setTimeout(function () {
                            window.location.reload();
                        }, 2000);
                    } else {
                        layer.msg(result.info, {icon: 5});
                    }
                }
            });
        });

        //绑定sku
        $('.bind-sku').click(function() {
            $('.p-storage-position').html($(this).attr('data-storage-position'));
            $('input[name="sku"]').val($(this).attr('data-sku'));
            $('input[name="sku_old"]').val($(this).attr('data-sku'));
            $('input[name="export_tax_rebate"]').val($(this).attr('data-export-tax-rebate'));
            $('.sure-bind').attr('data-storage-position',$(this).attr('data-storage-position'));
        });

        //确认绑定sku
        $('.sure-bind').click(function() {
            var storage_position = $(this).attr('data-storage-position');
            var _self = $(this);
            _self.attr('disabled', 'disabled').html('保存中...');
            $.ajax({
                type: "post",
                url: 'Warehouse/StockIn/storage_bind_sku',
                data: {
                    storage_position: storage_position, 
                    sku: $.trim($('input[name="sku"]').val()),
                    sku_old: $.trim($('input[name="sku_old"]').val()),
                    export_tax_rebate: $.trim($('input[name="export_tax_rebate"]').val())
                },
                dataType: "json",
                success: function (result) {
                    if (result.status) {
                        layer.msg(result.info, {icon: 6});
                        setTimeout(function () {
                            window.location.reload();
                        }, 2000);
                    } else {
                        layer.msg(result.info, {icon: 5});
                    }
                    _self.removeAttr('disabled').html('确定');
                }
            });
        })
    });
</script>
